
#include "XmlRpc.h"
#include <iostream>
using namespace XmlRpc;

int main(int argc, char* argv[]) {
  if (argc != 3) {
    std::cerr << "Usage: HelloClient serverHost serverPort\n";
    return -1;
  }
  int port = atoi(argv[2]);
 

 
  XmlRpcClient c(argv[1], port);
  XmlRpcValue noArgs, result;
  if (c.execute("system.listMethods", noArgs, result))
    std::cout << "\nMethods:\n " << result << "\n\n";
  else
    std::cout << "Error calling 'listMethods'\n\n";





 
  XmlRpcValue numbers;
  numbers[0] = "print 1";
  numbers[1] = "";
  if (c.execute("run_code", numbers, result))
  {
    std::cout << result.size();
    std::cout << "run_code result = " << "return code: "<<result[0]<<"\n stdout:" << result[1]<<"\n stderr:" << result[2]<< "\n\n";
  }
  else
  {
    std::cout << "Error calling 'run_code'\n\n";
    exit(1);
  }
  while(int(result[0])>0)
      if(c.execute("cont", numbers, result))
      {
        std::cout << result.size();
        std::cout << "cont result = " << int(result[0]) << result[1] << result[2] << "\n\n";
      }
      else
        std::cout << "Error calling 'cont'\n\n";

  if (c.execute("end", noArgs, result))
    std::cout << "end result = " << result<< "\n\n";
  else
    std::cout << "Error calling 'end'\n\n";














  return 0;
}
